package com.neusoft.clouduserfeign.feign;

import com.neusoft.clouduserfeign.config.FeignConfig;
import com.neusoft.clouduserfeign.dto.LoginRequest;
import com.neusoft.clouduserfeign.dto.Result;
import com.neusoft.clouduserfeign.dto.User;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户服务Feign客户端
 * 通过服务名调用，实现负载均衡
 * 集成容错机制和服务降级
 */
@FeignClient(
    name = "cloud-user-service",
    contextId = "userServiceClient",
    fallback = UserServiceClientFallback.class,
    configuration = FeignConfig.class
)
public interface UserServiceClient {
    
    /**
     * 用户登录
     */
    @PostMapping("/api/users/login")
    Result<User> login(@RequestBody LoginRequest request);
    
    /**
     * 创建用户
     */
    @PostMapping("/api/users")
    Result<Void> createUser(@RequestBody User user, @RequestParam("createBy") String createBy);

    /**
     * 更新用户信息
     */
    @PutMapping("/api/users/{userId}")
    Result<Void> updateUser(@PathVariable("userId") String userId,
                           @RequestBody User user,
                           @RequestParam("updateBy") String updateBy);

    /**
     * 根据用户ID查询用户
     */
    @GetMapping("/api/users/{userId}")
    Result<User> getUserByUserId(@PathVariable("userId") String userId);
    
    /**
     * 删除用户（逻辑删除）
     */
    @DeleteMapping("/api/users/{userId}")
    Result<Void> deleteUser(@PathVariable("userId") String userId, @RequestParam("updateBy") String updateBy);

    /**
     * 查询用户列表
     */
    @GetMapping("/api/users")
    Result<List<User>> getUserList(@RequestParam(value = "userType", required = false) String userType,
                                   @RequestParam(value = "status", required = false) String status,
                                   @RequestParam(value = "keyword", required = false) String keyword);

    /**
     * 启用/禁用用户
     */
    @PutMapping("/api/users/{userId}/status")
    Result<Void> updateUserStatus(@PathVariable("userId") String userId,
                                  @RequestParam("status") String status,
                                  @RequestParam("updateBy") String updateBy);

    /**
     * 修改密码
     */
    @PutMapping("/api/users/{userId}/password")
    Result<Void> changePassword(@PathVariable("userId") String userId,
                               @RequestBody Object request,
                               @RequestParam("updateBy") String updateBy);

    /**
     * 重置密码（管理员操作）
     */
    @PutMapping("/api/users/{userId}/reset-password")
    Result<Void> resetPassword(@PathVariable("userId") String userId,
                              @RequestBody Object request,
                              @RequestParam("updateBy") String updateBy);

    /**
     * 检查权限
     */
    @GetMapping("/api/users/{userId}/permission")
    Result<Boolean> checkPermission(@PathVariable("userId") String userId,
                                    @RequestParam(value = "operation", required = false) String operation);
}
